﻿namespace MyWebLog.Logic.Services
{
    using DatabaseAbstraction;
    using DatabaseAbstraction.Interfaces;
    using MyWebLog.Logic.QueryProviders;

    /// <summary>
    /// This is the base class for all My WebLog services
    /// </summary>
    public abstract class MyWebLogService
    {
        /// <summary>
        /// Data service instance
        /// </summary>
        protected IDatabaseService Data { get; private set; }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="data">
        /// An initialized data service instance
        /// </param>
        protected MyWebLogService(IDatabaseService data)
        {
            Data = data;
        }

        /// <summary>
        /// Fill the static query library
        /// </summary>
        /// <remarks>
        /// This is a hook into the logic library, designed to be called by the web application on startup.
        /// The static query library is filled once, then reused by any DatabaseService-extending implementation.
        /// 
        /// Although this uses the SQLiteDatabaseService concrete class, the static library is shared among all
        /// implementations; its use here does not constrain one to use SQLite.
        /// </remarks>
        public static void SetUpDatabase()
        {
            SQLiteDatabaseService.FillStaticQueryLibrary(typeof(BlogQueryProvider), typeof(SecurityQueryProvider));
        }
    }
}